/**
 * 
 */
package com.pxingg.exception;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * The class <code>XException</code> and its subclasses are a form of <code>Exception</code> that indicates conditions that a reasonable application might want to catch.
 * 
 */
public class XException extends Exception
{
    /**
     * define a serial version UID
     */
    private static final long serialVersionUID = 1L;
    /**
     * The log of this class
     */
    static Log log = LogFactory.getLog(XException.class);

    /**
     * 把异常中的堆栈信息给转换成字符串，得到e.printStackTrace()的结果
     * 
     * @param e
     *            需要获取信息的异常信息
     * @return e.printStackTrace()的结果字符串
     */
    public static String getStack(final Throwable e)
    {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final PrintStream ps = new PrintStream(baos);
        e.printStackTrace(ps);

        return baos.toString();
    }

    /**
     * Constructs a new XException with <code>null</code> as its detail message. The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}.
     */
    public XException()
    {
        super();
    }

    /**
     * Constructs a new XException with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}.
     * 
     * @param message
     *            the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
     */
    public XException(final String message)
    {
        super(message);
    }

    /**
     * Constructs a new XException with the specified detail message and cause.
     * <p>
     * Note that the detail message associated with <code>cause</code> is <i>not</i> automatically incorporated in this exception's detail message.
     * 
     * @param message
     *            the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
     * @param cause
     *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <tt>null</tt> value is permitted, and indicates that the cause is nonexistent or unknown.)
     */
    public XException(final String message, final Throwable cause)
    {
        super(message, cause);
    }

    /**
     * Constructs a new XException with the specified cause and a detail message of <tt>(cause==null ? null : cause.toString())</tt> (which typically contains the class and detail message of <tt>cause</tt>). This constructor is useful for exceptions that are little more than wrappers for other throwables (for example,
     * {@link java.security.PrivilegedActionException}).
     * 
     * @param cause
     *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <tt>null</tt> value is permitted, and indicates that the cause is nonexistent or unknown.)
     */
    public XException(final Throwable cause)
    {
        super(cause);
    }
}
